import threading
import time

num=0
mutex=threading.Lock() #创建一个锁

class Mythread(threading.Thread):
    def run(self):
        global num
        if mutex.acquire(1):  #锁住成功, 没有锁成功就一直等待
            for i in range(1000000):
                num+=1
            mutex.release() #释放锁
        print(num)

#创建5个线程干活
mythread=[]
for i in range(5):
    t=Mythread()
    t.start()
    mythread.append(t)

for t in mythread:
    t.join()
print('game over')



